1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module gdk.DisplayManager;
26 
27 private import gdk.Display;
28 private import gdk.c.functions;
29 public  import gdk.c.types;
30 private import glib.ListSG;
31 private import glib.Str;
32 private import gobject.ObjectG;
33 private import gobject.Signals;
34 private import std.algorithm;
35 
36 
37 /**
38  * A singleton object that offers notification when displays appear or
39  * disappear.
40  * 
41  * You can use [func@Gdk.DisplayManager.get] to obtain the `GdkDisplayManager`
42  * singleton, but that should be rarely necessary. Typically, initializing
43  * GTK opens a display that you can work with without ever accessing the
44  * `GdkDisplayManager`.
45  * 
46  * The GDK library can be built with support for multiple backends.
47  * The `GdkDisplayManager` object determines which backend is used
48  * at runtime.
49  * 
50  * In the rare case that you need to influence which of the backends
51  * is being used, you can use [func@Gdk.set_allowed_backends]. Note
52  * that you need to call this function before initializing GTK.
53  * 
54  * ## Backend-specific code
55  * 
56  * When writing backend-specific code that is supposed to work with
57  * multiple GDK backends, you have to consider both compile time and
58  * runtime. At compile time, use the `GDK_WINDOWING_X11`, `GDK_WINDOWING_WIN32`
59  * macros, etc. to find out which backends are present in the GDK library
60  * you are building your application against. At runtime, use type-check
61  * macros like GDK_IS_X11_DISPLAY() to find out which backend is in use:
62  * 
63  * ```c
64  * #ifdef GDK_WINDOWING_X11
65  * if (GDK_IS_X11_DISPLAY (display))
66  * {
67  * // make X11-specific calls here
68  * }
69  * else
70  * #endif
71  * #ifdef GDK_WINDOWING_MACOS
72  * if (GDK_IS_MACOS_DISPLAY (display))
73  * {
74  * // make Quartz-specific calls here
75  * }
76  * else
77  * #endif
78  * g_error ("Unsupported GDK backend");
79  * ```
80  */
81 public class DisplayManager : ObjectG
82 {
83 	/** the main Gtk struct */
84 	protected GdkDisplayManager* gdkDisplayManager;
85 
86 	/** Get the main Gtk struct */
87 	public GdkDisplayManager* getDisplayManagerStruct(bool transferOwnership = false)
88 	{
89 		if (transferOwnership)
90 			ownedRef = false;
91 		return gdkDisplayManager;
92 	}
93 
94 	/** the main Gtk struct as a void* */
95 	protected override void* getStruct()
96 	{
97 		return cast(void*)gdkDisplayManager;
98 	}
99 
100 	/**
101 	 * Sets our main struct and passes it to the parent class.
102 	 */
103 	public this (GdkDisplayManager* gdkDisplayManager, bool ownedRef = false)
104 	{
105 		this.gdkDisplayManager = gdkDisplayManager;
106 		super(cast(GObject*)gdkDisplayManager, ownedRef);
107 	}
108 
109 
110 	/** */
111 	public static GType getType()
112 	{
113 		return gdk_display_manager_get_type();
114 	}
115 
116 	/**
117 	 * Gets the singleton `GdkDisplayManager` object.
118 	 *
119 	 * When called for the first time, this function consults the
120 	 * `GDK_BACKEND` environment variable to find out which of the
121 	 * supported GDK backends to use (in case GDK has been compiled
122 	 * with multiple backends).
123 	 *
124 	 * Applications can use [func@set_allowed_backends] to limit what
125 	 * backends wil be used.
126 	 *
127 	 * Returns: The global `GdkDisplayManager` singleton
128 	 */
129 	public static DisplayManager get()
130 	{
131 		auto __p = gdk_display_manager_get();
132 
133 		if(__p is null)
134 		{
135 			return null;
136 		}
137 
138 		return ObjectG.getDObject!(DisplayManager)(cast(GdkDisplayManager*) __p);
139 	}
140 
141 	/**
142 	 * Gets the default `GdkDisplay`.
143 	 *
144 	 * Returns: a `GdkDisplay`
145 	 */
146 	public Display getDefaultDisplay()
147 	{
148 		auto __p = gdk_display_manager_get_default_display(gdkDisplayManager);
149 
150 		if(__p is null)
151 		{
152 			return null;
153 		}
154 
155 		return ObjectG.getDObject!(Display)(cast(GdkDisplay*) __p);
156 	}
157 
158 	/**
159 	 * List all currently open displays.
160 	 *
161 	 * Returns: a newly
162 	 *     allocated `GSList` of `GdkDisplay` objects
163 	 */
164 	public ListSG listDisplays()
165 	{
166 		auto __p = gdk_display_manager_list_displays(gdkDisplayManager);
167 
168 		if(__p is null)
169 		{
170 			return null;
171 		}
172 
173 		return new ListSG(cast(GSList*) __p);
174 	}
175 
176 	/**
177 	 * Opens a display.
178 	 *
179 	 * Params:
180 	 *     name = the name of the display to open
181 	 *
182 	 * Returns: a `GdkDisplay`, or %NULL
183 	 *     if the display could not be opened
184 	 */
185 	public Display openDisplay(string name)
186 	{
187 		auto __p = gdk_display_manager_open_display(gdkDisplayManager, Str.toStringz(name));
188 
189 		if(__p is null)
190 		{
191 			return null;
192 		}
193 
194 		return ObjectG.getDObject!(Display)(cast(GdkDisplay*) __p);
195 	}
196 
197 	/**
198 	 * Sets @display as the default display.
199 	 *
200 	 * Params:
201 	 *     display = a `GdkDisplay`
202 	 */
203 	public void setDefaultDisplay(Display display)
204 	{
205 		gdk_display_manager_set_default_display(gdkDisplayManager, (display is null) ? null : display.getDisplayStruct());
206 	}
207 
208 	/**
209 	 * Emitted when a display is opened.
210 	 *
211 	 * Params:
212 	 *     display = the opened display
213 	 */
214 	gulong addOnDisplayOpened(void delegate(Display, DisplayManager) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
215 	{
216 		return Signals.connect(this, "display-opened", dlg, connectFlags ^ ConnectFlags.SWAPPED);
217 	}
218 }